//
//  XJOriginalView.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/22.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJOriginalView.h"


@implementation XJOriginalView

-(void)setStatusViewModel:(XJStatusViewModel *)statusViewModel{

    _statusViewModel = statusViewModel;
    NSURL *url = [NSURL URLWithString:statusViewModel.statusModel.user.profile_image_url];    
    [self.iconImg sd_setImageWithURL:url];
    self.nameLabel.text = statusViewModel.statusModel.user.name;
    self.memberImg.image = statusViewModel.memberImage;
    self.sourceLabel.text = statusViewModel.sourceText;
    self.contentLabel.text = statusViewModel.statusModel.text;
    self.timeLabel.text = statusViewModel.statusModel.created_at;
}

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{

    self.backgroundColor = [UIColor whiteColor];
    //头像
    UIImageView *iconImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_small"]];
    self.iconImg = iconImg;
    iconImg.layer.cornerRadius = 18;
    iconImg.layer.masksToBounds = YES;
    //昵称
    UILabel *nameLabel = [UILabel textColor:[UIColor orangeColor] font:nameLabelFont];
    self.nameLabel = nameLabel;
    //会员图片
    UIImageView *memberImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_icon_membership"]];
    self.memberImg = memberImg;
    //时间
    UILabel *timeLabel = [UILabel textColor:[UIColor darkGrayColor] font:timeLabelFont];
    self.timeLabel = timeLabel;
    //来源
    UILabel *sourceLabel = [UILabel textColor:[UIColor darkGrayColor] font:sourceLabelFont];
    self.sourceLabel = sourceLabel;
    //内容
    UILabel *contentLabel = [UILabel textColor:[UIColor blackColor] font:contentLabelFont maxWidth:screenW - 2* statusCellMargin];
    self.contentLabel = contentLabel;
    //认证
    UIImageView *verifiedImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_vip"]];
    self.verifiedImg = verifiedImg;
    
    [self addSubview:iconImg];
    [self addSubview:nameLabel];
    [self addSubview:memberImg];
    [self addSubview:timeLabel];
    [self addSubview:sourceLabel];
    [self addSubview:contentLabel];
    [self addSubview:verifiedImg];
    
    [iconImg makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.leading.equalTo(statusCellMargin);
        make.width.height.equalTo(iconSizeWidth);
    }];
    [nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(iconImg);
        make.leading.equalTo(iconImg.trailing).offset(statusCellMargin);
    }];
    [memberImg makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(nameLabel);
        make.leading.equalTo(nameLabel.trailing).offset(statusCellMargin);
    }];
    [timeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(nameLabel);
        make.bottom.equalTo(iconImg);
    }];
    [sourceLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(timeLabel);
        make.leading.equalTo(timeLabel.trailing).offset(statusCellMargin);
    }];
    [contentLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(iconImg);
        make.top.equalTo(iconImg.bottom).offset(statusCellMargin);
    }];
    [verifiedImg makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(iconImg.trailing).offset(-4);
        make.centerY.equalTo(iconImg.bottom).offset(-4);
    }];
    [self makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(contentLabel.bottom).offset(statusCellMargin);
    }];
    

}

@end
